var n = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(n) {
    return typeof n;
} : function(n) {
    return n && "function" == typeof Symbol && n.constructor === Symbol && n !== Symbol.prototype ? "symbol" : typeof n;
}, t = "function" == typeof Symbol && "symbol" == n(Symbol.iterator) ? function(t) {
    return void 0 === t ? "undefined" : n(t);
} : function(t) {
    return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : void 0 === t ? "undefined" : n(t);
};

!function(n, e) {
    "object" == ("undefined" == typeof exports ? "undefined" : t(exports)) && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : (void 0).Ald = e();
}(0, function() {
    function n() {
        "function" == typeof hn && "" === j && hn().then(function(n) {
            28 === n.length && (j = n, wx.setStorageSync("aldstat_op", n));
        });
    }
    function e(n) {
        this.app = n;
    }
    function o(n) {
        H = y(), Q = n, an = n.scene, this.aldstat = new e(this);
    }
    function r(t) {
        n();
        var e;
        e = t.scene != an, an = t.scene, N = 0, Q = t, K = t.query.ald_share_src, V = t.query.aldsrc || "", 
        W = t.query.ald_share_src, on || rn || fn || (T = !1), on = !1, (0 !== C && Date.now() - C > 3e4 || e) && (rn || (R = y(), 
        U = Date.now(), cn = 0)), 0 !== C && Date.now() - C < 3e4 && (Y = !0), t.query.ald_share_src && "1044" == t.scene && t.shareTicket ? wx.getShareInfo({
            shareTicket: t.shareTicket,
            success: function(n) {
                z = n, D("event", "ald_share_click", JSON.stringify(n));
            }
        }) : t.query.ald_share_src && D("event", "ald_share_click", 1), "" === F && wx.getSetting({
            withCredentials: !0,
            success: function(n) {
                n.authSetting["scope.userInfo"] && wx.getUserInfo({
                    withCredentials: !0,
                    success: function(n) {
                        var t = w();
                        F = n, t.ufo = S(n), B = v(n.userInfo.avatarUrl.split("/")), g(t);
                    }
                });
            }
        }), x("app", "show");
    }
    function i() {
        n(), C = Date.now(), "" === F && wx.getSetting({
            success: function(n) {
                n.authSetting["scope.userInfo"] && wx.getUserInfo({
                    withCredentials: !0,
                    success: function(n) {
                        F = n, B = v(n.userInfo.avatarUrl.split("/"));
                        var t = w();
                        t.ufo = S(n), g(t);
                    }
                });
            }
        }), x("app", "hide");
    }
    function a(n) {
        $++, D("event", "ald_error_message", n);
    }
    function s(n) {
        tn = n;
    }
    function u() {
        un = Date.now(), Z = L ? this.$mp.page.route : this.route, b("page", "show"), Y = !1;
    }
    function c() {
        nn = Z, cn = Date.now() - un;
    }
    function f() {
        nn = Z, cn = Date.now() - un;
    }
    function h() {
        D("event", "ald_pulldownrefresh", 1);
    }
    function l() {
        D("event", "ald_reachbottom", 1);
    }
    function p(n) {
        rn = !0;
        var t = m(n.path), e = {};
        for (var o in Q.query) "ald_share_src" !== o && "ald_share_op" !== o || (e[o] = Q.query[o]);
        var r = "";
        if (r = -1 == n.path.indexOf("?") ? n.path + "?" : n.path.substr(0, n.path.indexOf("?")) + "?", 
        "" !== t) for (var o in t) e[o] = t[o];
        e.ald_share_src ? -1 == e.ald_share_src.indexOf(J) && e.ald_share_src.length < 200 && (e.ald_share_src = e.ald_share_src + "," + J) : e.ald_share_src = J, 
        I.useOpen && (e.ald_share_op ? -1 == e.ald_share_op.indexOf(j) && e.ald_share_op.length < 200 && (e.ald_share_op = e.ald_share_op + "," + j) : e.ald_share_op = j);
        for (var i in e) -1 == i.indexOf("ald") && (r += i + "=" + e[i] + "&");
        return n.path = r + (I.useOpen ? "ald_share_op=" + e.ald_share_op + "&" : "") + "ald_share_src=" + e.ald_share_src, 
        D("event", "ald_share_status", n), n;
    }
    function d() {
        function n() {
            return Math.floor(65536 * (1 + Math.random())).toString(16).substring(1);
        }
        return n() + n() + n() + n() + n() + n() + n() + n();
    }
    function g(n) {
        function t() {
            return new Promise(function(n, t) {
                var e = {
                    AldStat: "MiniApp-Stat",
                    se: E || "",
                    op: j || "",
                    img: B
                };
                "" === k || (e.ai = k);
            });
        }
        N++, n.at = R, n.uu = J, n.v = M, n.ak = I.app_key.replace(/(\t)|(\s)/g, ""), n.wsr = Q, 
        n.ifo = T, n.rq_c = N, n.ls = H, n.te = P, n.et = Date.now(), n.st = Date.now(), 
        I.useOpen ? "" === j ? sn.push(t) : (wx.Queue.push(t), sn.concat()) : wx.Queue.push(t);
    }
    function w() {
        var n = {};
        for (var t in G) n[t] = G[t];
        return n;
    }
    function v(n) {
        for (var t = "", e = 0; e < n.length; e++) n[e].length > t.length && (t = n[e]);
        return t;
    }
    function y() {
        return "" + Date.now() + Math.floor(1e7 * Math.random());
    }
    function S(n) {
        var t = {};
        for (var e in n) "rawData" != e && "errMsg" != e && (t[e] = n[e]);
        return t;
    }
    function m(n) {
        if (-1 == n.indexOf("?")) return "";
        var t = {};
        return n.split("?")[1].split("&").forEach(function(n) {
            var e = n.split("=")[1];
            t[n.split("=")[0]] = e;
        }), t;
    }
    function _(n) {
        for (var e in n) if ("object" == t(n[e]) && null !== n[e]) return !0;
        return !1;
    }
    function x(n, t) {
        var e = w();
        e.ev = n, e.life = t, e.ec = $, e.dr = Date.now() - U, "show" == t && (e.uo = I.useOpen), 
        V && (e.qr = V, e.sr = V), K && (e.usr = K), g(e);
    }
    function b(n, t) {
        var e = w();
        e.ev = n, e.life = t, e.pp = Z, e.pc = nn, e.dr = Date.now() - U, (rn || fn) && (e.so = 1), 
        fn = !1, rn = !1, tn && "{}" != JSON.stringify(tn) && (e.ag = tn), V && (e.qr = V, 
        e.sr = V), K && (e.usr = K), Y && (e.ps = 1), X ? e.pdr = cn : (en = Z, X = !0, 
        e.ifp = X, e.fp = Z, e.pdr = 0), g(e);
    }
    function D(n, t, e) {
        var o = w();
        o.ev = n, o.tp = t, o.dr = Date.now() - U, e && (o.ct = e), g(o);
    }
    function q(n, t, e) {
        if (n[t]) {
            var o = n[t];
            n[t] = function(n) {
                e.call(this, n, t), o.call(this, n);
            };
        } else n[t] = function(n) {
            e.call(this, n, t);
        };
    }
    function O(n) {
        var t = {};
        for (var e in n) "onLaunch" !== e && "onShow" !== e && "onHide" !== e && "onError" !== e && (t[e] = n[e]);
        return t.onLaunch = function(t) {
            o.call(this, t), "function" == typeof n.onLaunch && n.onLaunch.call(this, t);
        }, t.onShow = function(t) {
            r.call(this, t), n.onShow && "function" == typeof n.onShow && n.onShow.call(this, t);
        }, t.onHide = function() {
            i.call(this), n.onHide && "function" == typeof n.onHide && n.onHide.call(this);
        }, t.onError = function(t) {
            a.call(this, t), n.onError && "function" == typeof n.onError && n.onError.call(this, t);
        }, t;
    }
    function A(n) {
        var t = {};
        for (var e in n) "onLoad" !== e && "onShow" !== e && "onHide" !== e && "onUnload" !== e && "onPullDownRefresh" !== e && "onReachBottom" !== e && "onShareAppMessage" !== e && (t[e] = n[e]);
        return t.onLoad = function(t) {
            s.call(this, t), "function" == typeof n.onLoad && n.onLoad.call(this, t);
        }, t.onShow = function(t) {
            u.call(this), "function" == typeof n.onShow && n.onShow.call(this, t);
        }, t.onHide = function(t) {
            c.call(this), "function" == typeof n.onHide && n.onHide.call(this, t);
        }, t.onUnload = function(t) {
            f.call(this), "function" == typeof n.onUnload && n.onUnload.call(this, t);
        }, t.onReachBottom = function(t) {
            l(), n.onReachBottom && "function" == typeof n.onReachBottom && n.onReachBottom.call(this, t);
        }, t.onPullDownRefresh = function(t) {
            h(), n.onPullDownRefresh && "function" == typeof n.onPullDownRefresh && n.onPullDownRefresh.call(this, t);
        }, n.onShareAppMessage && "function" == typeof n.onShareAppMessage && (t.onShareAppMessage = function(t) {
            var e = n.onShareAppMessage.call(this, t);
            return void 0 === e ? (e = {}, e.path = this.route) : void 0 === e.path && (e.path = this.route), 
            p.call(this, e);
        }), t;
    }
    var I = require("./ald-stat-conf");
    void 0 === wx.Queue && (wx.Queue = new function() {
        this.concurrency = 4, this.queue = [], this.tasks = [], this.activeCount = 0;
        var n = this;
        this.push = function(t) {
            this.tasks.push(new Promise(function(e, o) {
                var r = function() {
                    n.activeCount++, t().then(function(n) {
                        e(n);
                    }).then(function() {
                        n.next();
                    });
                };
                n.activeCount < n.concurrency ? r() : n.queue.push(r);
            }));
        }, this.all = function() {
            return Promise.all(this.tasks);
        }, this.next = function() {
            n.activeCount--, n.queue.length > 0 && n.queue.shift()();
        };
    }(), wx.Queue.all()), "" === I.app_key && console.error("请在ald-stat-conf.js文件中填写小程序统计/广告监测平台创建小程序后生成的app_key，请参考接入文档 http://doc.aldwx.com 小程序统计平台-快速接入指南！"), 
    I.useOpen && console.warn("提示：开启了useOpen配置后，如果不上传用户OpendID则不会上报数据，上传方式：http://doc.aldwx.com 小程序统计/广告监测平台-快速接入指南-上传OpenID！");
    var M = "7.3.6", P = "wx", k = void 0 === wx.getAccountInfoSync ? "" : wx.getAccountInfoSync().miniProgram.appId.split("").map(function(n) {
        return n.charCodeAt(0) + 9;
    }).join("-"), L = !1, R = y(), H = "", U = Date.now(), C = 0, E = "", j = function() {
        var n = "";
        try {
            n = wx.getStorageSync("aldstat_op");
        } catch (n) {}
        return n;
    }(), B = "", N = 0, Q = "", T = "", J = function() {
        var n = "";
        try {
            n = wx.getStorageSync("aldstat_uuid");
        } catch (t) {
            n = "uuid_getstoragesync";
        }
        if (n) T = !1; else {
            n = d();
            try {
                wx.setStorageSync("aldstat_uuid", n), T = !0;
            } catch (n) {
                wx.setStorageSync("aldstat_uuid", "uuid_getstoragesync");
            }
        }
        return n;
    }(), K = "", V = "", W = "", $ = 0, z = "", F = "", G = {}, X = !1, Y = !1, Z = "", nn = "", tn = "", en = "", on = !0, rn = !1, an = "", sn = new function() {
        this.request = [], this.updata = !1, this.push = function(t) {
            this.request.length >= 8 && !this.updata && (this.updata = !0, n()), this.request.length >= 10 ? (this.request.shift(), 
            this.request.push(t)) : this.request.push(t);
        }, this.concat = function() {
            this.request.map(function(n) {
                wx.Queue.push(n);
            }), this.request = [];
        };
    }(), un = 0, cn = 0, fn = !1;
    [ {
        name: "scanCode"
    }, {
        name: "chooseAddress"
    }, {
        name: "chooseImage"
    }, {
        name: "previewImage"
    }, {
        name: "chooseInvoiceTitle"
    }, {
        name: "chooseInvoice"
    } ].forEach(function(n) {
        n.fn = wx[n.name];
        var t = n.name;
        Object.defineProperty(wx, t, {
            get: function() {
                return fn = !0, n.fn;
            }
        });
    });
    var hn = "";
    wx.aldstat = new e("");
    try {
        var ln = wx.getSystemInfoSync();
        G.br = ln.brand, G.pm = ln.model, G.pr = ln.pixelRatio, G.ww = ln.windowWidth, G.wh = ln.windowHeight, 
        G.lang = ln.language, G.wv = ln.version, G.wvv = ln.platform, G.wsdk = ln.SDKVersion, 
        G.sv = ln.system;
    } catch (n) {}
    return wx.getNetworkType({
        success: function(n) {
            G.nt = n.networkType;
        }
    }), wx.getSetting({
        success: function(n) {
            n.authSetting["scope.userLocation"] ? wx.getLocation({
                type: "wgs84",
                success: function(n) {
                    G.lat = n.latitude, G.lng = n.longitude, G.spd = n.speed;
                }
            }) : I.getLocation && wx.getLocation({
                type: "wgs84",
                success: function(n) {
                    G.lat = n.latitude, G.lng = n.longitude, G.spd = n.speed;
                }
            });
        }
    }), e.prototype.sendEvent = function(n, e) {
        if ("" !== n && "string" == typeof n && n.length <= 255) if ("string" == typeof e && e.length <= 255) D("event", n, e); else if ("object" == (void 0 === e ? "undefined" : t(e))) {
            if (JSON.stringify(e).length >= 255) return void console.error("自定义事件参数不能超过255个字符，请参考接入文档 http://doc.aldwx.com 小程序统计平台-快速接入指南-自定义事件！");
            if (_(e)) return void console.error("事件参数内部只支持Number、String等类型，请参考接入文档 http://doc.aldwx.com 小程序统计平台-快速接入指南-自定义事件！");
            for (var o in e) "number" == typeof e[o] && (e[o] = e[o] + "s##");
            D("event", n, JSON.stringify(e));
        } else void 0 === e ? D("event", n, !1) : console.error("事件参数必须为String、Object类型，且参数长度不能超过255个字符，请参考接入文档 http://doc.aldwx.com 小程序统计平台-快速接入指南-自定义事件！"); else console.error("事件名称必须为String类型且不能超过255个字符，请参考接入文档 http://doc.aldwx.com 小程序统计平台-快速接入指南-自定义事件！");
    }, e.prototype.sendSession = function(n) {
        if ("" !== n && n) {
            E = n;
            var t = w();
            t.tp = "session", t.ct = "session", t.ev = "event", "" === F ? wx.getSetting({
                success: function(n) {
                    n.authSetting["scope.userInfo"] ? wx.getUserInfo({
                        success: function(n) {
                            t.ufo = S(n), B = v(n.userInfo.avatarUrl.split("/")), "" !== z && (t.gid = z), g(t);
                        }
                    }) : "" !== z && (t.gid = z, g(t));
                }
            }) : (t.ufo = F, "" !== z && (t.gid = z), g(t));
        } else console.error("请传入从后台获取的session_key");
    }, e.prototype.sendOpenid = function(n) {
        if ("" !== n && n && 28 === n.length) {
            j = n, wx.setStorageSync("aldstat_op", n);
            var t = w();
            t.tp = "openid", t.ev = "event", t.ct = "openid", g(t);
        } else console.error("OpenID不符合规则，请参考接入文档 http://doc.aldwx.com 小程序统计/广告监测平台-快速接入指南！");
    }, e.prototype.setOpenid = function(t) {
        "function" == typeof t && (hn = t, n());
    }, I.plugin ? {
        App: function(n) {
            function t(t) {
                return n.apply(this, arguments);
            }
            return t.toString = function() {
                return n.toString();
            }, t;
        }(function(n) {
            return App(O(n));
        }),
        Page: function(n) {
            function t(t) {
                return n.apply(this, arguments);
            }
            return t.toString = function() {
                return n.toString();
            }, t;
        }(function(n) {
            return Page(A(n));
        }),
        MpvueApp: function(n) {
            return L = !0, O(n);
        },
        MpvuePage: function(n) {
            return A(n);
        }
    } : void function() {
        var n = App, t = Page, e = Component;
        App = function(t) {
            q(t, "onLaunch", o), q(t, "onShow", r), q(t, "onHide", i), q(t, "onError", a), n(t);
        }, Page = function(n) {
            var e = n.onShareAppMessage;
            q(n, "onLoad", s), q(n, "onUnload", f), q(n, "onShow", u), q(n, "onHide", c), q(n, "onReachBottom", l), 
            q(n, "onPullDownRefresh", h), void 0 !== e && null !== e && (n.onShareAppMessage = function(n) {
                if (void 0 !== e) {
                    var t = e.call(this, n);
                    return void 0 === t ? (t = {}, t.path = Z) : void 0 === t.path && (t.path = Z), 
                    p(t);
                }
            }), t(n);
        }, Component = function(n) {
            try {
                var t = n.methods.onShareAppMessage;
                q(n.methods, "onLoad", s), q(n.methods, "onUnload", f), q(n.methods, "onShow", u), 
                q(n.methods, "onHide", c), q(n.methods, "onReachBottom", l), q(n.methods, "onPullDownRefresh", h), 
                void 0 !== t && null !== t && (n.methods.onShareAppMessage = function(n) {
                    if (void 0 !== t) {
                        var e = t.call(this, n);
                        return void 0 === e ? (e = {}, e.path = Z) : void 0 === e.path && (e.path = Z), 
                        p(e);
                    }
                }), e(n);
            } catch (t) {
                e(n);
            }
        };
    }();
});